//
//  GetNetStatusPlugin.m
//  PCDBankSix
//
//  Created by APPLE on 2023/8/21.
//

#import "GetNetStatusPlugin.h"

@implementation GetNetStatusPlugin

- (void)handler:(id)data andContext:(PCDContext *)context ResponseCallback:(WVJBResponseCallback )responseCallback{
    NSDictionary *dictData = (NSDictionary *)data;
    NSString *strCallback = dictData[@"success"];
    
    RealReachability * reachability   = [RealReachability sharedInstance];
    [reachability startNotifier];
    ReachabilityStatus internetStatus = [reachability currentReachabilityStatus];
    BOOL  reachable;
    NSString * statu;
    if (internetStatus == RealStatusViaWiFi) {
        statu = @"WIFI";
        reachable = YES;
    }else if (internetStatus == RealStatusViaWWAN) {
        statu = @"WWAN";//[PCDDevice getNetType];
        reachable = YES;
    }else {
        statu = @"NoNet";
        reachable = NO;
    }
    NSDictionary *dict = @{
                           @"reachable":@(reachable),
                           @"networkType":statu
                           };
    
    evaluateJavaScriptOnMainThread(self, strCallback, [dict JSONRepresentation]);
    
}


@end
